package giaodien;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Toolkit;
import java.awt.event.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;

import javax.swing.*;
import javax.swing.border.BevelBorder;
import javax.swing.plaf.metal.MetalIconFactory;

import sukien.EventButton;

import com.l2fprod.common.swing.StatusBar;

public class GiaoDien extends JFrame{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	EventButton eve;
	JMenuBar menu;
	JToolBar toolbar;
	public JButton newbtn;
	public JButton openbtn;
	public MyButton downbtn;
	public MyButton addbtn;
	public MyButton peoplebtn;
	public MyButton backbtn;
	public MyButton tobtn;
	public MyButton clockbtn;
	public MyButton phongtobtn;
	public MyButton savebtn;
	public MyButton closebtn;
	public MyButton cutbtn;
	public MyButton stopbtn;
	public MyButton thangbtn;
	public MyButton numberbtn;
	DateFormat datefomat=new SimpleDateFormat("dd/MM/yyyy");
	DateFormat datefomat1=new SimpleDateFormat("hh:mm:ss");
	Calendar cal=Calendar.getInstance();
	String date;
	String date1;
	StatusBar statusBar;
	JLabel lb;
//	public JPanel pn=new JPanel();
	public DangNhap dangnhap;
	public GiaoDien() {
		eve=new EventButton(this);
		dangnhap=new DangNhap(this);
		toolbar=toolBar();
		menu=menuBar();
		setLayout(new BorderLayout(5,5));
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setExtendedState(JFrame.MAXIMIZED_BOTH);
		this.setIconImage(Toolkit.getDefaultToolkit().getImage("image/Apps-krfb-icon.png"));
		this.pack();
		this.setVisible(true);
		this.setJMenuBar(menu);
		this.setResizable(false);
		this.add(toolbar,BorderLayout.NORTH);
		StatusBar statusBar=statusBar();
		this.add(statusBar,BorderLayout.SOUTH);
		dangnhap.setVisible(true);
		Listener();
	}
	public void Listener(){
		dangnhap.btnHuy.addActionListener((ActionListener)eve);
		dangnhap.btnDangNhap.addActionListener((ActionListener)eve);
		this.addWindowListener(new WindowListener() {
			
			@Override
			public void windowOpened(WindowEvent arg0) {
				
			}
			
			@Override
			public void windowIconified(WindowEvent arg0) {
				
			}
			
			@Override
			public void windowDeiconified(WindowEvent arg0) {
				
			}
			
			@Override
			public void windowDeactivated(WindowEvent arg0) {
				
			}
			
			@Override
			public void windowClosing(WindowEvent arg0) {
				int n=JOptionPane.showConfirmDialog(null, "Bạn có muốn thoát không", "Cảnh cáo", JOptionPane.YES_NO_OPTION);
				if(n==JOptionPane.YES_OPTION){
					System.exit(0);
				}		
			}
			
			@Override
			public void windowClosed(WindowEvent arg0) {
			}
			
			@Override
			public void windowActivated(WindowEvent arg0) {
				
			}
		});
	}
	public JMenuBar menuBar(){
		JMenuBar menubar1=new JMenuBar();
		JMenu menuFile=new JMenu("File");
		menuFile.setMnemonic(KeyEvent.VK_F);
		menubar1.add(menuFile);
		
		JMenu menuEdit=new JMenu("Edit");
		menuEdit.setMnemonic(KeyEvent.VK_E);
		menubar1.add(menuEdit);
		
		JMenu menuView=new JMenu("View");
		menuView.setMnemonic(KeyEvent.VK_V);
		menubar1.add(menuView);
		
		return menubar1;
	}
	public JToolBar toolBar(){
		JToolBar tolbar=new JToolBar();
		newbtn=new JButton(MetalIconFactory.getFileChooserHomeFolderIcon());
		newbtn.setToolTipText("New");
		openbtn=new JButton(MetalIconFactory.getFileChooserUpFolderIcon());
		openbtn.setToolTipText("Open");
		downbtn=new MyButton("","down.png");
		downbtn.setToolTipText("Down");
		addbtn=new MyButton("","add.png");
		addbtn.setToolTipText("Add");
		backbtn=new MyButton("","back.png");
		backbtn.setToolTipText("Back");
		tobtn=new MyButton("","to.png");
		tobtn.setToolTipText("To");
		clockbtn=new MyButton("","clock.png");
		clockbtn.setToolTipText("Clock");
		savebtn=new MyButton("","save.png");
		savebtn.setToolTipText("Save");
		phongtobtn=new MyButton("","phongto.png");
		phongtobtn.setToolTipText("PhongTo");
		peoplebtn=new MyButton("","people.png");
		peoplebtn.setToolTipText("User");
		closebtn=new MyButton("","close.png");
		closebtn.setToolTipText("Close");
		cutbtn=new MyButton("","cut.png");
		cutbtn.setToolTipText("Cut");
		stopbtn=new MyButton("","stop.png");
		stopbtn.setToolTipText("Stop");
		thangbtn=new MyButton("","thang.png");
		thangbtn.setToolTipText("Bản đồ");
		tolbar.add(newbtn);
		tolbar.add(openbtn);
		tolbar.add(savebtn);
		tolbar.add(cutbtn);
		tolbar.add(downbtn);
		tolbar.add(stopbtn);
		
		JPanel lb1=new JPanel(new BorderLayout());
		JComboBox<Object> com =new JComboBox<Object>();
		//com.setPrototypeDisplayValue("XXXXX");
		//com.setMinimumSize(com.getMinimumSize());
		//com.setEnabled(true);
		com.setPreferredSize(new Dimension(5,0));
		com.setSize(5, 5);
		lb1.add(com,BorderLayout.WEST);
		tolbar.add(lb1);
		tolbar.add(addbtn);
		tolbar.add(peoplebtn);
		tolbar.add(backbtn);
		tolbar.add(tobtn);
		tolbar.add(clockbtn);
		tolbar.add(phongtobtn);
		tolbar.add(closebtn);
		tolbar.add(thangbtn);
		return tolbar;
	}
	public StatusBar statusBar(){
		date=datefomat.format(cal.getTime());
		date1=datefomat1.format(cal.getTime());
		StatusBar statusBar=new StatusBar();
		statusBar.setBorder(new BevelBorder(JToolBar.TOP));
		lb=new JLabel("Welcome");
		lb.setForeground(Color.BLUE);
		//JProgressBar pro= progressBar();
		statusBar.add(lb);
		//statusBar.add(pro);
		JLabel lb2=new JLabel("Ngày    "+date+"   Giờ "+date1);
		lb2.setForeground(Color.BLUE);
		statusBar.add(lb2);
		return statusBar;
	}
}
